var timer = null, timer2 = null
	function load(obj, type, func){
		return window.attachEvent ? obj.attachEvent('on' + type, func) : obj.addEventListener(type, func);
	}
	function getStyle(obj, attr){
		return obj.currentStyle ? obj.currentStyle[attr] : getComputedStyle(obj, false)[attr];
	}
	function getClass(obj, cN){
		var elems = obj.getElementsByTagName('*'),
			elemsLen = elems.length,
			els = [];
		for(var i = 0; i < elemsLen; i++){
			var cl = elems[i].className.split(' ') ? elems[i].className.split(' ')[0] : elems[i].className;
			if(cl == cN){
				els.push(elems[i]);
			}
		}
		return els;
	}
	
	function getStyle(obj, attr){
		return obj.currentStyle ? obj.currentStyle[attr] : getComputedStyle(obj, false)[attr];
	}
	
	function startMove(obj, attr, iTarget){
		clearInterval(timer);
		var iCur = parseInt(getStyle(obj, attr));
		return timer = setInterval(function(){
			var iSpeed = 0;
			iSpeed = parseInt(getStyle(obj, attr)) < iTarget ? 8 : -8;
			if(Math.abs(parseInt(getStyle(obj, attr))-iTarget) < Math.abs(iSpeed)){
				obj.style[attr] = iTarget + 'px';	
				clearInterval(timer);
			}else{
				obj.style[attr] = parseInt(getStyle(obj, attr)) + iSpeed + 'px';	
			}
		},10);
	}
	
	function main(){
		var oDiv = document.getElementById('KinS'),
			oLogos = getClass(oDiv, 'logo'),
			oLogosNav = getClass(oDiv, 'logo_nav'),
			oLogosNavLis = oLogosNav[0].getElementsByTagName('li'),
			oLogosNavLisLen = oLogosNavLis.length,
			j = 0;	
		oLogosNavLis[0].getElementsByTagName('a')[0].style.background = '#89c000';
		var automove = function(){
			clearInterval(timer2);
			timer2 = setInterval(function(){
				move(oLogosNavLis[j++], oLogos[0], timer);
				if(j == oLogosNavLisLen) j = 0;
			}, 3000);
		};
		for(var i = 0; i < oLogosNavLisLen; i++){
			oLogosNavLis[i].index = i;
			oLogosNavLis[i].onmouseover = function(){
				clearInterval(timer2);
				move(this, oLogos[0]);
			}
			oLogosNavLis[i].onmouseout = function(){
				j = this.index < oLogosNavLisLen - 1 ? this.index + 1 : 0;
				automove();
			}
		}
		automove();
	}
	
	function move(obj, _parent){
		var oAs = obj.parentNode.getElementsByTagName('a'),
			oAsLen = oAs.length;
		for(var j = 0; j < oAsLen; j++){
			oAs[j].style.background = '#666';
		}
		obj.getElementsByTagName('a')[0].style.background = '#89c000';
		startMove(_parent, 'top', _parent.getElementsByTagName('li')[0].offsetHeight*(obj.index + 1) -  _parent.offsetHeight);
	}
	load(window, 'load', main);